package homework.day04;

import java.util.Random;
import java.util.Scanner;

/**
 * @author ThinkBook
 */
public class Test08 {
    public static void main(String[] args) {
//定义长度为20的数组，存放随机数
        int[] arr = new int[20];
//生成随机数，对数组元素赋值
        Random r = new Random();
        for (int i = 0;i<arr.length;i++){
            int n= r.nextInt(20-1+1)+1;
            arr[i] = n;
        }
//程序一直运行
//创建Scanner对象，用来在控制台输入数据
        Scanner scanner = new Scanner(System.in);
        int index = -1 ;
        while (true){
        int num = scanner.nextInt();
            if (num ==-1){
                System.out.println("程序停止运行");
                break;
            }else {
                for (int i = 0; i < arr.length; i++) {
                    if (num == arr[i]) {
                        index = i;
                        break;
                    }
                }
                if (index>0){
                    System.out.println("用户数字所在数组下标位置:"+index);
                    continue;
                }else {
                    System.out.println("用户数据不存在");
                    continue;
                }
            }
        }
    }
}

